var count=1;
var delStr=new Array();
function removeObj(obj){
	$(obj).parent('p').remove();
}
function delObj(obj){
	if(typeof(delStr)!="undefined"){
		delStr.splice($.inArray($(obj).prev('span').attr("data-value"), delStr),1);
	}
	$(obj).parent('p').remove();
}
function toChange(obj){
	if($(obj)[0].files[0] !=undefined){
		$(obj).next().text("文件大小："+$(obj)[0].files[0].size+"b");
		if($(obj)[0].files[0].size>30720000){
			layer.alert("单个文件不能超过30M，请重新选择");
			removeObj(obj);
		}
	}else{
		$(obj).next().text("");
		$(obj).parent('p').remove();
	}
	
}
function initLoad(){
	$("#addBtn").click(function(){
		var html="";
		if(count>11){
			layer.alert("只能上传10个附件哦！");
			return false;
		}
		
		html+='<p><input type="file" name="files" id="files'+count+'" style="position: absolute;" onchange="toChange(this)" accept="image/x-png,image/gif,image/jpeg,image/bmp">';
		html+=' <span  style="vertical-align :middle;margin-left :45%" id="size'+count+'"></span>';
		html+='<a  style="float:right;" onclick="removeObj(this)">';
		html+='  <span class="glyphicon glyphicon-minus-sign" style="color: red;vertical-align :middle;" ></span>';
		html+=' </a> </p>';
		$("#formContent").append(html);
		$("#files"+count).click();
		count++;
	});
	
	$("#addBtn2").click(function(){
		var html="";
		if(count>2){
			layer.alert("只能上传1张图片哦！");
			return false;
		}
		
		html+='<p><input type="file" name="files" id="files'+count+'" style="position: absolute;" onchange="toChange(this)" accept="image/x-png,image/gif,image/jpeg,image/bmp">';
		html+=' <span  style="vertical-align :middle;margin-left :45%" id="size'+count+'"></span>';
		html+='<a  style="float:right;" onclick="removeObj(this)">';
		html+='  <span class="glyphicon glyphicon-minus-sign" style="color: red;vertical-align :middle;" ></span>';
		html+=' </a> </p>';
		$("#formContent2").append(html);
		$("#files"+count).click();
		count++;
	});
}
